// pages/home/home.js
function getRandomColor() {
  const rgb = []
  for (let i = 0; i < 3; ++i) {
    let color = Math.floor(Math.random() * 256).toString(16)
    color = color.length === 1 ? '0' + color : color
    rgb.push(color)
  }
  return '#' + rgb.join('')
}
Page({
  /**
   * 页面的初始数据
   */
  data: {
    show: false,
    position: 'center',
    round: true,
    overlay: true,
    src: '',
    video:null,
    danmuList:
    [{
      text: '第 1s 出现的弹幕',
      color: '#ff0000',
      time: 1
    }, {
      text: '第 3s 出现的弹幕',
      color: '#ff00ff',
      time: 3
    }],
    data:[
      {
        text:'排球扣球脚步',
        imgsrc:'http://172.81.245.195:8888/group1/M00/00/02/rFH1w2C9zt2AULmxAADi4jkGB-Q153.jpg',
        videosrc:'http://172.81.245.195:8888/group1/M00/00/02/rFH1w2C9zf2AHAb-ABRtcoRrFuo018.mp4'
      },
      {
        text:'排球垫球',
        imgsrc:'http://172.81.245.195:8888/group1/M00/00/01/rFH1w2C3kvyAbgbTAABOC-aTEJs533.jpg',
        videosrc:'http://172.81.245.195:8888/group1/M00/00/01/rFH1w2C3k0WAA0n9ACX0CbpkiaA122.mp4'
      },
      {
        text:'排球传球',
        imgsrc:'http://172.81.245.195:8888/group1/M00/00/02/rFH1w2C-VQaAB1QsAABkvJsTQN4383.jpg',
        videosrc:'http://172.81.245.195:8888/group1/M00/00/02/rFH1w2C-VSOAFxBXAB6-STEsi44479.mp4'
      },
      {
        text:'排球鱼跃',
        imgsrc:'http://172.81.245.195:8888/group1/M00/00/02/rFH1w2C-VBOAbVVaAACNe1ip6us809.jpg',
        videosrc:'http://172.81.245.195:8888/group1/M00/00/02/rFH1w2C-U7CAI5hUACosW5t6yW8762.mp4'
      },
      {
        text:'排球扣球',
        imgsrc:'http://172.81.245.195:8888/group1/M00/00/02/rFH1w2C-VwqAOOLJAABr2VBuDD8769.jpg',
        videosrc:'http://172.81.245.195:8888/group1/M00/00/02/rFH1w2C-Vz-ACwveAB7hCj8qyHY711.mp4'
      },
      {
        text:'精彩瞬间',
        imgsrc:'http://172.81.245.195:8888/group1/M00/00/02/rFH1w2C-V7OANP4hAABMoIOxSOM127.jpg',
        videosrc:'http://172.81.245.195:8888/group1/M00/00/02/rFH1w2C-V8eAIDBYABDt8eAmUL0464.mp4'
      },
      {
        text:'大运会男排',
        imgsrc:'http://172.81.245.195:8888/group1/M00/00/02/rFH1w2C-WJGAB28AAAA76y6t0vM228.jpg',
        videosrc:'http://172.81.245.195:8888/group1/M00/00/02/rFH1w2C-WKWADybZABzJRa43ZFU275.mp4'
      },
      {
        text:'大运会精彩瞬间',
        imgsrc:'http://172.81.245.195:8888/group1/M00/00/02/rFH1w2C-WMOAO_e8AAA7jNb8QIg681.jpg',
        videosrc:'http://172.81.245.195:8888/group1/M00/00/02/rFH1w2C-WN2AdzOiAB131rZTRic498.mp4'
      },
    ]
  },
  bindInputBlur(e) {
    this.inputValue = e.detail.value
  },

  bindButtonTap() {
    const that = this
    wx.chooseVideo({
      sourceType: ['album', 'camera'],
      maxDuration: 60,
      camera: ['front', 'back'],
      success(res) {
        that.setData({
          src: res.tempFilePath
        })
      }
    })
  },

  bindVideoEnterPictureInPicture() {
    console.log('进入小窗模式')
  },

  bindVideoLeavePictureInPicture() {
    console.log('退出小窗模式')
  },

  bindPlayVideo() {
    console.log('1')
    this.videoContext.play()
  },
  bindSendDanmu() {
    this.videoContext.sendDanmu({
      text: this.inputValue,
      color: getRandomColor()
    })
  },

  videoErrorCallback(e) {
    console.log('视频错误信息:')
    console.log(e.detail.errMsg)
  },
  
  popup(e) {
    console.log(e);
    let video=e.currentTarget.dataset.vsrc;
    const position = e.currentTarget.dataset.position
    this.setData({
      show: true,
      video:video
    })
  },
  exit(e){
    this.setData({
      show:false,
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    this.videoContext = wx.createVideoContext('myVideo')
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },
  inputValue: '',
  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})